<?php
namespace plugin\videoappdownload\admin;

use plugin\videoappdownload\model\PluginVideoappdownloadAd as models ; 
use plugin\videoappdownload\validate\AdValidate as validates ;
use app\admin\common\Baseadmin;

use think\facade\Db; 

class Ad extends Baseadmin
{
      public function   lists(){  
             $request= (new validates())->IsCheck('lists');
             $field="";
             $map   =[];
   
             $map[] = ["status", "=", 2 ]; 
             //map =排序   field = 空则全部输出 order排序  page 每页条数
             $model =(new models())->paginate($map,$field,$order='category_id desc',$page=20);
             $data['list']=$model;
             ajaxmsg('ok', 200,$data);  
      }

                public function   switch_open(){  
             $request= (new validates())->IsCheck('switch_open');
             $field=["open"];
             $map   =[];
             $map[] = ["id", "=", input('request.id') ]; 
             $find=(new models())->finds($map,$field);
			       if(!$find){
			      	    ajaxmsg('内容不存在', 0);  
			        }
          
             $open = $find['open']=='1' ? '0' : '1';
             $request['open']= $open;
             $map[] = ["id", "=", input('request.id') ]; 
             $model =(new models())->updates($map,$request,$field);
              if($model){
               ajaxmsg('成功', 200,$open);
              }
               ajaxmsg('失败', 0);  
      } 

          public function views(){  
              $request= (new validates())->IsCheck();
              $field='';
              $map   =[];
              $map[] = ["id", "=", input('request.id') ]; 
              $model =(new models())->finds($map,$field);
              $data['find']=$model;
              if ($model) {
                     ajaxmsg('成功', 200,$data);
              } 
                  ajaxmsg('内容不存在', 0);
        }
         public function edit(){  
             $request= (new validates())->IsCheck('edit');
             $field='';
             $map   =[];
             $map[] = ["id", "=", input('request.id') ]; 
             $request["status"]= 2;$request["userip"]= request()->ip();;
 
             if (input('request.id') > 0) {
                  //编辑
				  //$field=["open",'name']; 示例
				  // $map[] = ['name', 'like', "%".input('request.name')."%" ]; 搜索示例
				  // $map[] = ['id', '=', input('request.select')]; 普通示例
                   $model =(new models())->updates($map,$request,$field);
              } else {
                  //新增
                   $model =(new models())->adds($request,$field);
             } 
                if($model){
                  ajaxmsg('成功', 200);
               }
               ajaxmsg('失败', 0);
        }
       
       
        public function dels(){  
              $request= (new validates())->IsCheck();
              
              (new models())->where('id',$request['id'])->delete();
               ajaxmsg('成功', 200);
        }
       
 
    //控制器方法
    
    
    
}